﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:FirstFloor.ModernUI.Windows.Controls">

    <Style x:Key="SliderRepeatButtonStyle" TargetType="RepeatButton">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RepeatButton">
                    <Rectangle Fill="Transparent"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="BaseSliderThumbStyle" TargetType="Thumb">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Background" Value="{DynamicResource SliderThumbBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource SliderThumbBorder}"/>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource SliderThumbBackgroundHover}"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource SliderThumbBorderHover}"/>
                        </Trigger>
                        <Trigger Property="IsDragging" Value="True">
                            <Setter Property="Background" Value="{DynamicResource SliderThumbBackgroundDragging}"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource SliderThumbBorderDragging}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource SliderThumbBackgroundDisabled}"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource SliderThumbBorderDisabled}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="HorizontalSliderThumbStyle" TargetType="Thumb" BasedOn="{StaticResource BaseSliderThumbStyle}">
        <Setter Property="Height" Value="22"/>
        <Setter Property="Width" Value="11"/>
    </Style>

    <Style x:Key="VerticalSliderThumbStyle" TargetType="Thumb" BasedOn="{StaticResource BaseSliderThumbStyle}">
        <Setter Property="Height" Value="11"/>
        <Setter Property="Width" Value="22"/>
    </Style>
    
    <Style TargetType="Slider">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Slider">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="true">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"
                                               MinHeight="{TemplateBinding Slider.MinHeight}"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TickBar x:Name="TopTick"
                                     Grid.Row="0"
                                     Visibility="Collapsed"
                                     Placement="Top"
                                     Fill="{DynamicResource SliderTick}"
                                     Height="4"/>
                            <TickBar x:Name="BottomTick"
                                     Grid.Row="2"
                                     Visibility="Collapsed"
                                     Placement="Bottom"
                                     Fill="{DynamicResource SliderTick}"
                                     Height="4"/>
                            <Border x:Name="TrackBackground"
                                    Grid.Row="1"
                                    Margin="5,0"
                                    VerticalAlignment="center"
                                    BorderBrush="{DynamicResource SliderTrackBorder}"
                                    BorderThickness="1"
                                    Background="{DynamicResource SliderTrackBackground}"
                                    Height="4.0">
                                <Canvas Margin="-6,-1">
                                    <Rectangle x:Name="PART_SelectionRange"
                                               Fill="{DynamicResource SliderSelectionBackground}"
                                               Height="4.0"
                                               Visibility="Hidden"
                                               StrokeThickness="1.0"
                                               Stroke="{DynamicResource SliderSelectionBorder}"/>
                                </Canvas>
                            </Border>
                            <Track Grid.Row="1"
                                   Name="PART_Track">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                                  Command="{x:Static Slider.DecreaseLarge}"/>
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                                  Command="{x:Static Slider.IncreaseLarge}"/>
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb"
                                           Style="{StaticResource HorizontalSliderThumbStyle}"/>
                                </Track.Thumb>
                            </Track>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TickPlacement"
                                 Value="TopLeft">
                            <Setter TargetName="TopTick"
                                    Property="Visibility"
                                    Value="Visible"/>
                            <Setter TargetName="TrackBackground"
                                    Property="Margin"
                                    Value="5,2,5,0"/>
                        </Trigger>
                        <Trigger Property="TickPlacement"
                                 Value="BottomRight">
                            <Setter TargetName="BottomTick"
                                    Property="Visibility"
                                    Value="Visible"/>
                            <Setter TargetName="TrackBackground"
                                    Property="Margin"
                                    Value="5,0,5,2"/>
                        </Trigger>
                        <Trigger Property="TickPlacement"
                                 Value="Both">
                            <Setter TargetName="TopTick"
                                    Property="Visibility"
                                    Value="Visible"/>
                            <Setter TargetName="BottomTick"
                                    Property="Visibility"
                                    Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsSelectionRangeEnabled"
                                 Value="true">
                            <Setter TargetName="PART_SelectionRange"
                                    Property="Visibility"
                                    Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="false">
                            <Setter TargetName="TopTick"
                                    Property="Fill"
                                    Value="{DynamicResource SliderTickDisabled}"/>
                            <Setter TargetName="BottomTick"
                                    Property="Fill"
                                    Value="{DynamicResource SliderTickDisabled}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Orientation"
                     Value="Vertical">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Slider}">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    SnapsToDevicePixels="true">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="Auto"
                                                          MinWidth="{TemplateBinding Slider.MinWidth}"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <TickBar x:Name="TopTick"
                                             Grid.Column="0"
                                             Visibility="Collapsed"
                                             Placement="Left"
                                             Fill="{DynamicResource SliderTick}"
                                             Width="4"/>
                                    <TickBar x:Name="BottomTick"
                                             Grid.Column="2"
                                             Visibility="Collapsed"
                                             Placement="Right"
                                             Fill="{DynamicResource SliderTick}"
                                             Width="4"/>
                                    <Border Name="TrackBackground"
                                            Grid.Column="1"
                                            Margin="0,5"
                                            HorizontalAlignment="center"
                                            BorderBrush="{DynamicResource SliderTrackBorder}"
                                            BorderThickness="1"
                                            Background="{DynamicResource SliderTrackBackground}"
                                            Width="4.0">

                                        <Canvas Margin="-1,-6">
                                            <Rectangle x:Name="PART_SelectionRange"
                                                       Fill="{DynamicResource SliderSelectionBackground}"
                                                       Width="4.0"
                                                       Visibility="Hidden"
                                                       StrokeThickness="1.0"
                                                       Stroke="{DynamicResource SliderSelectionBorder}"/>
                                        </Canvas>
                                    </Border>

                                    <Track Grid.Column="1"
                                           Name="PART_Track">
                                        <Track.DecreaseRepeatButton>
                                            <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                                          Command="{x:Static Slider.DecreaseLarge}"/>
                                        </Track.DecreaseRepeatButton>
                                        <Track.IncreaseRepeatButton>
                                            <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                                          Command="{x:Static Slider.IncreaseLarge}"/>
                                        </Track.IncreaseRepeatButton>
                                        <Track.Thumb>
                                            <Thumb x:Name="Thumb"
                                                   Style="{StaticResource VerticalSliderThumbStyle}"/>
                                        </Track.Thumb>
                                    </Track>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="TickPlacement"
                                         Value="TopLeft">
                                    <Setter TargetName="TopTick"
                                            Property="Visibility"
                                            Value="Visible"/>
                                    <Setter TargetName="TrackBackground"
                                            Property="Margin"
                                            Value="2,5,0,5"/>
                                </Trigger>
                                <Trigger Property="TickPlacement"
                                         Value="BottomRight">
                                    <Setter TargetName="BottomTick"
                                            Property="Visibility"
                                            Value="Visible"/>
                                    <Setter TargetName="TrackBackground"
                                            Property="Margin"
                                            Value="0,5,2,5"/>
                                </Trigger>
                                <Trigger Property="TickPlacement"
                                         Value="Both">
                                    <Setter TargetName="TopTick"
                                            Property="Visibility"
                                            Value="Visible"/>
                                    <Setter TargetName="BottomTick"
                                            Property="Visibility"
                                            Value="Visible"/>
                                </Trigger>
                                <Trigger Property="IsSelectionRangeEnabled"
                                         Value="true">
                                    <Setter TargetName="PART_SelectionRange"
                                            Property="Visibility"
                                            Value="Visible"/>
                                </Trigger>
                                <Trigger Property="IsEnabled"
                                         Value="false">
                                    <Setter TargetName="TopTick"
                                            Property="Fill"
                                            Value="{DynamicResource SliderTickDisabled}"/>
                                    <Setter TargetName="BottomTick"
                                            Property="Fill"
                                            Value="{DynamicResource SliderTickDisabled}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>